<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<div id="ct">	
			
			<?php 
				$date_selected = false;
				$start_date;
				$end_date;
				if(post("date_selected")) {
					$start_date 	= post("start_date");
					$end_date 	= post("end_date");
					$date_selected = true;
				}
			?>
			
			<div style="margin-top:20px; margin-left:auto; margin-right:auto; width: 70%;">
				<h2>Show Cheap Tours</h2><br /><br />
				<form action="<?php echo curPageURL(); ?>" method="post">
					Select a start and end date too see cheapest tours at that date range;<br />
					<input type="date" id="start_date" name="start_date"/> - <input type="date" id="end_date" name="end_date"/>
					<input type="submit" id="date_selected" name="date_selected" value="Select" style="width: 90px; height:30px; margin-left: 10px;"/>
				</form>
			</div>
			
			<?php 
				if($date_selected == true) { ?>
					
				<table border="">
					<thead>
						<tr>
							<th>Tour name</th>
							<th>Hotel cost</th>
							<th>Transportation cost</th>
							<th>Total cost</th>
						</tr>
					</thead>
					<tbody>
						<?php 
							$query="select * from tour_cost tp inner join tour t on t.id=tp.tour_id 
										where t.start_date>'$start_date' and t.end_date<'$end_date' order by tp.total_price limit 5";
							
							$result = sql_query($query);
							
							while($tuple = mysql_fetch_assoc($result)) {
								?>
								<tr>
									<td><a href="tour_detail.php?id=<?php echo $tuple["tour_id"]; ?>"><?php echo $tuple["tour"]; ?></a></td>
									<td><?php echo $tuple["hotel_total_price"]; ?></td>
									<td><?php echo $tuple["transportation_total_price"]; ?></td>
									<td><?php echo $tuple["total_price"]; ?></td>
								</tr>
								<?php
							}
						?>
					</tbody>
				</table>
			<?php }?>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>